﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
// add
using System.IO;

namespace FormBaseLib
{
    public partial class FActionLog : Form
    {
        public string msTitle { get; private set; }
        public string msFile { get; private set; }
        public string msContent { get; private set; }

        public FActionLog()
        {
            InitializeComponent();
        }
        public void SetActionLog(CAction pAction)
        {
            msContent = pAction.msMessageLog;
            msFile = pAction.msFilename;
            msTitle = pAction.msActionName;
        }

        private void FActionLog_Load(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(msTitle))
                msTitle = "Text Reader";

            //txtFile.Text = msFile;
            //txtFile.Dock = DockStyle.Fill;
            //txtContent.Multiline = false;

            txtContent.Text = msTitle;
            txtContent.Dock = DockStyle.Fill;
            txtContent.Multiline = true;
            txtContent.ScrollBars = ScrollBars.Both;
            txtContent.Text = msContent;
        }
        private void menuCopy_Click(object sender, EventArgs e)
        {

            Clipboard.SetText(txtContent.Text);
            CProject.mApp.PopupMsg("Copy to clipboard.");
        }

        private void menuSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(msFile))
                CProject.mApp.PopupError("ERROR: File name is empty.");
            else
            {
                File.WriteAllText(msFile, txtContent.Text);
                CProject.mApp.PopupMsg(string.Format("Save to {0}.", msFile));
            }
        }

        private void menuRevert_Click(object sender, EventArgs e)
        {
            txtContent.Text = msContent;
            CProject.mApp.PopupMsg("Revert done.");
        }


    }
}
